var offset=0;
var limit=20;
var pagingLimit=20;//显示分页时的条数
var currentTotalElements=0;//当前显示总条数
var hasShowPages=false;//是否已显示分页
var firstLoadPages=true;//分页初始化时 不自动加载
var search_companyName=null;
var search_orderTypeName=null;
var otherService = new Array();
var updateOtherService = new Array();
var tips = new Array();
var updatetips = new Array();
var i = 0;
var t = 0;
var f = 0;
var n = 0;
var typepicture="";
var tipspicture="";
var typepicture_update = "";
var tipspicture_update = "";
$(function(){
	$("#searchButton").click(function(){
			search_orderTypeName=$("#orderTypeName").val();
			offset=0;
			initdata(false);
	});
	$(".query-jiant").click(function(){
		var src=$("#jiant").attr("src");
		if(src.indexOf("jiant2")>=0){
			$("#jiant").attr("src",ctx+"/assets/img/jiant.png");
			$(".choose").show(300);
		}else{
			$("#jiant").attr("src",ctx+"/assets/img/jiant2.png");
			$(".choose").hide(300);
		}
	});	

	$(document).on("keydown","body",function(){
		if(window.event.keyCode == 13){
			$("#searchButton").click();
		}
	});

	initdata(false);
});
$(document).on("click",".edit-button",function(){
		$(this).parent().hide();
		$(this).parent().parent().find(".edit-demo").show();
});	

$(document).on("click",".save-demo",function(){
	
//	$(this).parent().hide();
//	$(this).parent().parent().find(".show-demo").show();
	
	var this_button=$(this);
//	this_button.attr("disabled",true);
//	this_button.attr("disabled",false);
	this_button.parent().parent().hide();
	this_button.parent().parent().parent().find(".show-demo").find(".show_text").val("12");
//	this_button.parent().parent().parent().find(".show-demo .show-span").html(edit_demo);
	this_button.parent().parent().parent().find(".show-demo").show();
});

function initdata(isappend){
	$.ajax({
        url : ctx+'/errand/up/orderTypeDataUp',
        type:'GET',
        async:false,
        dataType : 'json',
        data : {
        	"typeName":search_orderTypeName,
        	"pager.offset":offset,
        	"limit":limit,
        },
        success : function(data){
			result = data.content;
        	var newcontent = "<tr><th class='col-xs-1' style='text-align:center;'>类型名称</th>" +
				"<th class='col-xs-1' style='text-align:center;'>添加时间</th>" +
				"<th class='col-xs-1' style='text-align:center;'>App显示顺序</th>" +
				"<th class='col-xs-1' style='text-align:center;'>操作</th></tr>";
        	$("#NoData").text("");
        	var totalElements=data.totalElements;
        	if(totalElements>0){
        		$(result).each(function(index,data){
        			var statusColor="btn-primary";
        		newcontent+="<tr><td colspan='4' style='border:none;'><div class='panel-group' id='accordion"+index+"'  role='tablist' aria-multiselectable='true'>"+
      			  "<div class='panel panel-default'>"+
      				"<div class='panel-heading' typeId='"+data.id+"' typeName='"+data.typeName+"' role='tab' id='heading"+index+"'>"+
      				  "<div class='panel-title'>"+
      					"<a data-toggle='collapse' data-parent='#accordion"+index+"' href='#collapse"+index+"' aria-expanded='true' aria-controls='collapse"+index+"'>"+
      					"<div class='col-md-3' style='text-align:center;'>"+data.typeName+"</div>" +
      					"<div class='col-md-3' style='text-align:center;'>"+data.created +"</div>" +
      					"<div class='col-md-3' style='text-align:center;'>"+data.typeSeq+"</div>" +
      					"<div class='col-md-2' style='text-align:right;'>"+
      					"<a href='#' typeId='"+data.id+"' typeName='"+data.typeName+"' typeSeq='"+data.typeSeq+"' class='btn btn-primary btn-xs  update'>编辑</a>&emsp;"
	        			+"<a href='#' typeId='"+data.id+"' typeName='"+data.typeName+"' class='btn btn-primary btn-xs delete'>删除</a>&emsp;"
	        			+"<button class='btn btn-primary btn-xs startService' typeId='"+data.id+"' typeName='"+ data.typeName +"'>开通类型</button>"+
      					"</div>"+
      					"</div>"+
      					"</a>"+
      				"</div>"+
      				"<div id='collapse"+index+"' class='panel-collapse collapse ' role='tabpanel' aria-labelledby='heading"+index+"'>";
      				if(isMainCompany){
					newcontent+="<div class='tab-content'>"+
			        				"<div class='container-fluid'>"+
			        			  		"<div class='row query-pad'>"+
			        			  			"<div class='col-xs-11' style='padding: 0px;'>"+
			        			  				"<div class='col-xs-4 input-query'>"+
				        			  				"<span>公司名称:</span>"+
				        			  				"<input type='text' class='form-control form-contb' id='companyName' name='companyName' placeholder='请输入公司名字'/>"+
			        			  				"</div>"+
		        			  				 "</div>"+
		        			  				 "<div class='col-xs-1' style='padding: 0px;'>"+
		        			  				 	"<div class='input-query-bttom'>"+
		        			  				 		"<button class='btn btn-primary btn-xs companySearchButton'>&emsp;查询&emsp;</button>"+
	        			  				 		"</div>"+
      			  				 		 "</div>"+
			        			  		"</div>"+
			        			  	 "</div>"+
		        			  	"</div>";
      				}
      			
      				newcontent+= "<div class='panel-body'>"+
      					"<div>"+
      						"<table class='table table-condensed table-striped'>"+
      							"<thead>"+
      								"<tr>"+
      									"<th class='col-xs-1' style='width:16%'>公司名称</th>"+
      									"<th class='col-xs-1' style='width:16%'>里程收费标准</th>"+
      									"<th class='col-xs-1' style='width:16%'>重量收费标准</th>"+
      									"<th class='col-xs-1' style='width:16%'>预支付</th>"+
      									"<th class='col-xs-1' style='width:16%'>计费类型</th>"+
      									"<th class='col-xs-2' style='width:20%'>操作</th>"+
      								"</tr>"+
      							"</thead>"+
      							"<tbody>"+
      							"</tbody>"+
      						"</table>"+
      						"<ul class='pagination pull-left pagination-sm pageshow"+index+"' data-index='"+index+"'><li><a>共0条数据</a></li></ul>"+
      			        	"<ul class='pagination pull-left pagination-sm pagedata"+index+"' data-index='"+index+"'></ul>"+
      			        	
      					"</div>"+
      				  "</div>"+
      				"</div>"+
      			  "</div>"+
      			"</div></td></tr>";
      		});
        	}else{
        	  	$("#NoData").text("当前页面暂无记录 ");
        	}
        	if(!isappend){
        		$("#orderType_tbody .grid-data").remove();
        	}
        	$("#orderType_tbody").html("");
        	$("#orderType_tbody").append(newcontent);
        	$("#orderType_tbody .grid-data").each(function(index,element){
        		$(element).fadeIn(200+(index*35));
        	});
        	if(!hasShowPages){
        		if(!isappend){
            		currentTotalElements=result.length;
            	}else{
            		if(currentTotalElements<totalElements){
            			currentTotalElements+=result.length;
            		}
            	}
        	}
        	if(hasShowPages){
    			firstLoadPages=true;
        		$(".pageshow li a").html("共"+totalElements+" 条数据");
        		$(".pagedata").paging(totalElements, {
        			format: '[< ncnnn >]',
        			perpage: pagingLimit,
        			page:(offset/limit)+1,
        			onSelect: function (page) {
        				limit=pagingLimit;
        				offset=(page-1)*limit;
        				if(!firstLoadPages){
        					initdata(false);
        				}
        				firstLoadPages=false;
        		    	return false;
        			},
        			onFormat: function (type) {
        				switch (type) {
        				case 'block': // n and c
        					if (!this.active)
        						return '';
        					else if (this.value != this.page)
        						return '<li><a href="#">' + this.value + '</a></li>';
        					return '<li class="active"><a href="#">' + this.value + '</a></li>';
        				case 'next': // >
        					return '<li><a href="#">&rsaquo;</a><li>';
        				case 'prev': // <
        						return '<li><a href="#">&lsaquo;</a><li>';
        				case 'first': // [
        						return '<li><a href="#">&laquo;</a><li>';
        				case 'last': // ]
        						return '<li><a href="#">&raquo;</a></li>';
        				}
        			}
        		});
        	}else{
        		hasShowPages=true;
        		$(".pageshow").show();
        		$(".pagedata").show();
        		$(".pageshow li a").html("共"+totalElements+" 条数据");
        		$(".pagedata").paging(totalElements, {
        			format: '[< ncnnn >]',
        			perpage: pagingLimit,
        			onSelect: function (page) {
        				limit=pagingLimit;
        				offset=(page-1)*limit;
        				if(!firstLoadPages){
        					initdata(false);
        				}
        				firstLoadPages=false;
        		    	return false;
        			},
        			onFormat: function (type) {
        				switch (type) {
        				case 'block': // n and c
        					if (!this.active)
        						return '';
        					else if (this.value != this.page)
        						return '<li><a href="#">' + this.value + '</a></li>';
        					return '<li class="active"><a href="#">' + this.value + '</a></li>';
        				case 'next': // >
        					return '<li><a href="#">&rsaquo;</a><li>';
        				case 'prev': // <
        						return '<li><a href="#">&lsaquo;</a><li>';
        				case 'first': // [
        						return '<li><a href="#">&laquo;</a><li>';
        				case 'last': // ]
        						return '<li><a href="#">&raquo;</a></li>';
        				}
        			}
        		});
        	}
        }
	});
}
$(document).on("click",".companySearchButton",function(){
	var p=	$(this).parent().parent().prev();
	var input=$(p).children('div').children('input');
	search_companyName=$(input).val();
	offset=0;
	var sss = $(this).parent().parent().parent().parent().parent().parent().parent()[0];
	panelHead($(sss).children("div:first-child")[0]);
});
$(document).on("click",".panel-heading",function(){
	panelHead(this);
});
function panelHead (obj) {
	var typeId=$(obj).attr("typeId");
	var typeName=$(obj).attr("typeName");
	var typeCompanyTbody=$(obj).parent().parent().children('div').children('div').children('div').children('div').children('table').children('tbody');
	var ul=$(obj).parent().parent().children('div').children('div').children('div').children('div').children('ul');
	var pageshow=$(ul[0]);
	var pagedata=$(ul[1]);
	$.ajax({
        url : ctx+'/errand/up/queryErrandTypeCompany',
        type:'GET',
        async:false,
        dataType : 'json',
        data : {
        	"typeId":typeId,
        	"companyName":search_companyName,
        	"pager.offset":offset,
        	"limit":limit,
        },
        success : function(result){
        	console.log(result);
        	var newcontent = '';
        	var totalElements=result.totalElements;
        	if(totalElements>0){
        		$(result.content).each(function(index,data){
				var updateButton=
        					"<div><a href='#' class='btn btn-primary btn-xs updateErrandType_company' " +
        					"typeId='"+typeId+"' typeName='"+typeName+"' companyId='"+data.companyId+"' " +
        					"companyName='"+data.companyName+
        					"' mileAreaId='"+data.mileAreaId+"' mileAreaName='"+data.mileAreaName+"' " +
        					"weightAreaId='"+data.weightAreaId+"' weightAreaName='"+data.weightAreaName+"'" +
        					"ifPrepay='"+data.ifPrepay+"' payType='"+data.payType+"'" +"' id='"+data.id+"'>编辑</a>";
        				
				var deleteButton = "&emsp;<a href='#'  data-value='"+data.id+"'  class='btn btn-primary  btn-xs deleteTypeCompany'>删除</a></div>";
				var prePay = "";
				var payType = "";
				if(data.ifPrepay == 1){
					prePay = "开启"
				}else{
					prePay = "关闭"
				}
				if(data.payType == 1){
					payType = "打表计费"
				}else{
					payType = "定价计费"
				}
				newcontent+="<tr>"+
	    				"<td>"+data.companyName+"</td>"+
						"<td>"+data.mileAreaName+"</td>"+
						"<td>"+data.weightAreaName+"</td>"+
						"<td>"+prePay+"</td>"+
						"<td>"+payType+"</td>"+
						"<td align='center'>"+updateButton+deleteButton+"</td>"+
					"</tr>";
        		});
        	}
        	$(typeCompanyTbody).html(newcontent);
        	firstLoadPages=true;
        	$(".pageshow"+$(pageshow).attr("data-index")+"").html("<li><a>共"+totalElements+"条数据</a></li>");
    		$(".pagedata"+$(pagedata).attr("data-index")+"").paging(totalElements, {
    			format: '[< ncnnn >]',
    			perpage: pagingLimit,
    			page:(offset/limit)+1,
    			onSelect: function (page) {
    				limit=pagingLimit;
    				offset=(page-1)*limit;
    				if(!firstLoadPages){
    					panelHead(obj);
    				}
    				firstLoadPages = false;
    		    	return false;
    			},
    			onFormat: function (type) {
    				switch (type) {
    				case 'block': // n and c
    					if (!this.active) {
    						return '';
    					} else if (this.value != this.page) {
    						return '<li><a href="javascript:;">' + this.value + '</a></li>';
    					}
    					return '<li class="active"><a href="javascript:;">' + this.value + '</a></li>';
    				case 'next': // >
    					return '<li><a href="javascript:;">&rsaquo;</a><li>';
    				case 'prev': // <
    						return '<li><a href="javascript:;">&lsaquo;</a><li>';
    				case 'first': // [
    						return '<li><a href="javascript:;">&laquo;</a><li>';
    				case 'last': // ]
    						return '<li><a href="javascript:;">&raquo;</a></li>';
    				}
    			}
    		});
        	
        }
	});
	search_companyName="";
}
function delBotton(serviceName){
	$("#"+serviceName).remove();
	otherService.splice($.inArray(serviceName, otherService),1);
	i--;
}
function deltr(tipName){
	$("tr#"+tipName).remove();
	tips.splice($.inArray(tipName, tips),1);
	t--;
}
$(document).on("click",".startService",function(){
	var typeName=$(this).attr("typeName");
	$("#errandTypeName").html(typeName);
	$("#errandTypeId").val($(this).attr("typeId"));
	$('#dialog_errandTypeCompany_create').modal();
});
$("#close_modal_company").click(function(){
	$('#dialog_errandTypeCompany_create').modal("hide");
});
$(document).on("click","#startService_company",function(){
	if($('#companyId_company').val()==null  || $('#companyId_company').val()==""){
		$.scojs_message("请选择开通公司！", $.scojs_message.TYPE_ERROR);
		return false;
	}
	if($('#mileAreaId').val()==null  || $('#mileAreaId').val()==""){
		$.scojs_message("请选择里程收费标准！", $.scojs_message.TYPE_ERROR);
		return false;
	}
	if($('#weightAreaId').val() ==null  || $('#weightAreaId').val()==""){
		$.scojs_message("请选择重量收费标准！", $.scojs_message.TYPE_ERROR);
		return false;
	}
	$.post(ctx+'/errand/up/openCompany',
			{'typeId':$('#errandTypeId').val(),
			'companyId':$('#companyId_company').val(),
			'mileAreaId':$('#mileAreaId').val(),
			'weightAreaId':$('#weightAreaId').val(),
			'mileAreaName':$('#mileAreaId').find("option:selected").text(),
			'weightAreaName':$('#weightAreaId').find("option:selected").text(),
			'companyName':$('#companyId_company').find("option:selected").text(),
			'ifPrepay':$("input[name='ifPrepay']:checked").val(),
			'payType':$("input[name='payType']:checked").val()},
			function(data){
	           if(data.success){
	                $.scojs_message(data.message, $.scojs_message.TYPE_OK);
	                setTimeout(function(){
						window.location.reload(true);
					}, 1000);
		       }else{
	                $.scojs_message(data.message, $.scojs_message.TYPE_ERROR);
		       }
		    },'json'
		);
});

//修改公司开通车型
$("#close_modal_company_update").click(function(){
	$('#dialog_errandTypeCompany_update').modal("hide");
});
$(document).on("click",".updateErrandType_company",function(){
	$("#name_update").html($(this).attr('typeName'));
	$("#typeId_update").val($(this).attr('typeId'));
	$("#companyId_update").val($(this).attr('companyId'));
	var companyName=$(this).attr('companyName');
	$("#companyName_update").html(companyName);
	var mileAreaId=$(this).attr('mileAreaId');
	var weightAreaId=$(this).attr('weightAreaId');
	var radioIfPrepay = $("input[name='ifPrepay_update']");
	var radioPayType = $("input[name='payType_update']");
	var ifPrepay=$(this).attr('ifPrepay');
	var payType=$(this).attr('payType');
	if(radioIfPrepay.length>0){
		for(var j=0;j<radioIfPrepay.length;j++){
			if(radioIfPrepay[j].value == ifPrepay){
				radioIfPrepay[j].checked=true;
			}else{
				radioIfPrepay[j].checked=false;
			}
		}
	}
	if(radioPayType.length>0){
		for(var j=0;j<radioPayType.length;j++){
			if(radioPayType[j].value == payType){
				radioPayType[j].checked=true;
			}else{
				radioPayType[j].checked=false;
			}
		}
	}
	$("#mileAreaId_update").val(mileAreaId);
	$("#weightAreaId_update").val(weightAreaId);
	$('#dialog_errandTypeCompany_update').modal();
});

 $(document).on("click","#startService_company_update",function(){
	 if($('#companyId_company').val()==null  || $('#companyId_company').val()==""){
			$.scojs_message("请选择开通公司！", $.scojs_message.TYPE_ERROR);
			return false;
		}
		if($('#mileAreaId').val()==null  || $('#mileAreaId').val()==""){
			$.scojs_message("请选择里程收费标准！", $.scojs_message.TYPE_ERROR);
			return false;
		}
		if($('#weightAreaId').val() ==null  || $('#weightAreaId').val()==""){
			$.scojs_message("请选择重量收费标准！", $.scojs_message.TYPE_ERROR);
			return false;
		}
		$.post(ctx+'/errand/up/updateOpenCompany',
				{'typeId':$('#typeId_update').val(),
				'companyId':$('#companyId_update').val(),
				'mileAreaId':$('#mileAreaId_update').val(),
				'weightAreaId':$('#weightAreaId_update').val(),
				'mileAreaName':$('#mileAreaId_update').find("option:selected").text(),
				'weightAreaName':$('#weightAreaId_update').find("option:selected").text(),
				'companyName':$('#companyName_update').html(),
				'ifPrepay':$("input[name='ifPrepay_update']:checked").val(),
				'payType':$("input[name='payType_update']:checked").val()},
				function(data){
		           if(data.success){
		                $.scojs_message(data.message, $.scojs_message.TYPE_OK);
		                setTimeout(function(){
							window.location.reload(true);
						}, 1000);
			       }else{
		                $.scojs_message(data.message, $.scojs_message.TYPE_ERROR);
		                setTimeout(function(){
							window.location.reload(true);
						}, 1000);
			       }
			    },'json'
			);
});
 $(document).on("click",".deleteTypeCompany",function(){
     thisButton_company = $(this);
     var confirm = $.scojs_confirm({
       content: "你真的要取消开通该车型吗？专车车型不会被删除!",
       action: deleteTypeCompany
     });
     confirm.show();
});
 
 function deleteTypeCompany() {
		if(thisButton_company.attr("data-value")==null  || thisButton_company.attr("data-value")==""){
			$.scojs_message("公司类型不存在！", $.scojs_message.TYPE_ERROR);
			return false;
		}
	    $.get(ctx + '/errand/up/deleteTypeCompany',{'typeCompanyId':thisButton_company.attr("data-value")},function(data){
         if(data.code==0){
         	thisButton_company.parent().parent().remove();
             $.scojs_message('公司类型取消成功', $.scojs_message.TYPE_OK);
              setTimeout(function(){
						window.location.reload(true);
					}, 800);
         } else {
             $.scojs_message(data.message, $.scojs_message.TYPE_ERROR);
         }
	    },'json');
	}
$(document).on("click",".typepicture",function(){
	typepicture=$(this).attr("src").replace(ctx,"");
	var typepictures=$(".typepicture");
	for(var i=0;i<typepictures.length;i++){
		var p=typepictures[i];
		$(p).parent().css("border","0px");
	}
	$(this).parent().css("border","1px solid red");
});
$(document).on("click",".typepicture_update",function(){
	typepicture_update=$(this).attr("src").replace(ctx,"");
	var typepictures=$(".typepicture_update");
	for(var i=0;i<typepictures.length;i++){
		var p=typepictures[i];
		$(p).parent().css("border","0px");
	}
	$(this).parent().css("border","1px solid red");
});
$(document).on("click",".tipspicture",function(){
	tipspicture=$(this).attr("src").replace(ctx,"");
	var tipspictures=$(".tipspicture");
	for(var i=0;i<tipspictures.length;i++){
		var p=tipspictures[i];
		$(p).parent().css("border","0px");
	}
	$(this).parent().css("border","1px solid red");
});
$(document).on("click",".tipspicture_update",function(){
	tipspicture_update=$(this).attr("src").replace(ctx,"");
	var tipspictures=$(".tipspicture_update");
	for(var i=0;i<tipspictures.length;i++){
		var p=tipspictures[i];
		$(p).parent().css("border","0px");
	}
	$(this).parent().css("border","1px solid red");
});
//保存
$(document).on("click","#addOrderType",function(){
	$('#dialog_modifyCash').modal();
});
$(document).on("click","#close_modal_memo",function(){
	$('#dialog_modifyCash').modal("hide");
});
$(document).on("click","#buyNeeds_required",function(){
	if($('#buyNeeds_required').is(':checked')){
		$('#buyNeeds_show').prop('checked','checked');
		$('#buyNeeds_show').prop('disabled',true);
	}
	else {
		$('#buyNeeds_show').prop('disabled',false);
	}
});
$(document).on("click","#startTime_required",function(){
	if($('#startTime_required').is(':checked')){
		$('#startTime_show').prop('checked','checked');
		$('#startTime_show').prop('disabled',true);
	}
	else {
		$('#startTime_show').prop('disabled',false);
	}
});
$(document).on("click","#start_required",function(){
	if($('#start_required').is(':checked')){
		$('#start_show').prop('checked','checked');
		$('#start_show').prop('disabled',true);
	}
	else {
		$('#start_show').prop('disabled',false);
	}
});
$(document).on("click","#protectPrice_required",function(){
	if($('#protectPrice_required').is(':checked')){
		$('#protectPrice_show').prop('checked','checked');
		$('#protectPrice_show').prop('disabled',true);
	}
	else {
		$('#protectPrice_show').prop('disabled',false);
	}
});
$(document).on("click","#startDetailed_required",function(){
	if($('#startDetailed_required').is(':checked')){
		$('#startDetailed_show').prop('checked','checked');
		$('#startDetailed_show').prop('disabled',true);
		$('#start_show').prop('checked','checked');
		$('#start_show').prop('disabled',true);
		$('#start_required').prop('checked','checked');
		$('#start_required').prop('disabled',true);
	}
	else {
		$('#startDetailed_show').prop('disabled',false);
//		$('#start_required').prop('disabled',false);
	}
});
$(document).on("click","#end_required",function(){
	if($('#end_required').is(':checked')){
		$('#end_show').prop('checked','checked');
		$('#end_show').prop('disabled',true);
	}
	else {
		$('#end_show').prop('disabled',false);
	}
});
$(document).on("click","#endDetailed_required",function(){
	if($('#endDetailed_required').is(':checked')){
		$('#endDetailed_show').prop('checked','checked');
		$('#endDetailed_show').prop('disabled',true);
		$('#end_show').prop('checked','checked');
		$('#end_show').prop('disabled',true);
		$('#end_required').prop('checked','checked');
		$('#end_required').prop('disabled',true);
	}
	else {
		$('#endDetailed_show').prop('disabled',false);
		$('#end_required').prop('disabled',false);
	}
});
$(document).on("click","#recipients_required",function(){
	if($('#recipients_required').is(':checked')){
		$('#recipients_show').prop('checked','checked');
		$('#recipients_show').prop('disabled',true);
	}
	else {
		$('#recipients_show').prop('disabled',false);
	}
});
$(document).on("click","#phone_required",function(){
	if($('#phone_required').is(':checked')){
		$('#phone_show').prop('checked','checked');
		$('#phone_show').prop('disabled',true);
	}
	else {
		$('#phone_show').prop('disabled',false);
	}
});
$(document).on("click","#weight_required",function(){
	if($('#weight_required').is(':checked')){
		$('#weight_show').prop('checked','checked');
		$('#weight_show').prop('disabled',true);
	}
	else {
		$('#weight_show').prop('disabled',false);
	}
});
$(document).on("click","#goodsCash_required",function(){
	if($('#goodsCash_required').is(':checked')){
		$('#goodsCash_show').prop('checked','checked');
		$('#goodsCash_show').prop('disabled',true);
	}
	else {
		$('#goodsCash_show').prop('disabled',false);
	}
});
$(document).on("click","#thanksCash_required",function(){
	if($('#thanksCash_required').is(':checked')){
		$('#thanksCash_show').prop('checked','checked');
		$('#thanksCash_show').prop('disabled',true);
	}
	else {
		$('#thanksCash_show').prop('disabled',false);
	}
});
$(document).on("click","#picture_required",function(){
	if($('#picture_required').is(':checked')){
		$('#picture_show').prop('checked','checked');
		$('#picture_show').prop('disabled',true);
	}
	else {
		$('#picture_show').prop('disabled',false);
	}
});
$(document).on("click","#content_required",function(){
	if($('#content_required').is(':checked')){
		$('#content_show').prop('checked','checked');
		$('#content_show').prop('disabled',true);
	}
	else {
		$('#content_show').prop('disabled',false);
	}
});
$(document).on("click","#addServices_required",function(){
	if($('#addServices_required').is(':checked')){
		$('#addServices_show').prop('checked','checked');
		$('#addServices_show').prop('disabled',true);
	}
	else {
		$('#addServices_show').prop('disabled',false);
	}
});
$(document).on("click","#save",function(){
	 	if($("#typeName").val()==null || $('#typeName').val().trim()==""){
	 		$.scojs_message("请填写名称", $.scojs_message.TYPE_ERROR);
	 		return false;
	 	}
	 	if($("#typeSeq").val()==null || $('#typeSeq').val().trim()==""){
	 		$.scojs_message("请填写显示顺序", $.scojs_message.TYPE_ERROR);
	 		return false;
	 	}
   		var orderTypeDetail =" [ "
   			if($('#buyNeeds').val().trim()!=null){
   	   		  orderTypeDetail += "{ ";
   	   		  orderTypeDetail += "  \"name\": \""+$('#buyNeeds').val().trim()+"\",";
   	   		  if($('#buyNeeds_required').is(':checked')){
   	   			orderTypeDetail += "  \"isShow\":1,";
   	   		    orderTypeDetail += "  \"isRequire\":1,";
   	   		  } else {
   	   		    if($('#buyNeeds_show').is(':checked')){
   	   			  orderTypeDetail += "  \"isShow\":1,";
   	   		    } else {
   	   		      orderTypeDetail += "  \"isShow\":0,";
   	   		    }
   	   		    orderTypeDetail += "  \"isRequire\":0,";
   	   		  }
   	   		  if($('#buyNeedsPrompt').val().trim()!=null) {
   	   			orderTypeDetail += "  \"prompt\": \""+$('#buyNeedsPrompt').val().trim()+"\",";
   	   		  }
   	   		  orderTypeDetail += "  \"seq\": 1";
   	   		  orderTypeDetail += " }";
   	   		}
   		if($('#startTime').val().trim()!=null){
   		  orderTypeDetail += ",{ ";
   		  orderTypeDetail += "  \"name\": \""+$('#startTime').val().trim()+"\",";
   		  if($('#startTime_required').is(':checked')){
   			orderTypeDetail += "  \"isShow\":1,";
   		    orderTypeDetail += "  \"isRequire\":1,";
   		  } else {
   		    if($('#startTime_show').is(':checked')){
   			  orderTypeDetail += "  \"isShow\":1,";
   		    } else {
   		      orderTypeDetail += "  \"isShow\":0,";
   		    }
   		    orderTypeDetail += "  \"isRequire\":0,";
   		  }
   		  if($('#appointmentPrompt').val().trim()!=null) {
   			orderTypeDetail += "  \"prompt\": \""+$('#appointmentPrompt').val().trim()+"\",";
   		  }
   		  orderTypeDetail += "  \"seq\": 2";
   		  orderTypeDetail += " }";
   		  console.debug($('#startTime').val());
   		}
   		if(!$('#start_required').is(':checked') && !$('#end_required').is(':checked')){
   			$.scojs_message("起点和终点必须选择一个必填", $.scojs_message.TYPE_ERROR);
	 		return false;
   		}
   		if($('#start').val().trim()!=null){
     		  orderTypeDetail += ",{ ";
     		  orderTypeDetail += "  \"name\": \""+$('#start').val().trim()+"\",";
     		  if($('#start_required').is(':checked')){
     			orderTypeDetail += "  \"isShow\":1,";
     		    orderTypeDetail += "  \"isRequire\":1,";
     		  } else {
     		    if($('#start_show').is(':checked')){
     			  orderTypeDetail += "  \"isShow\":1,";
     		    } else {
     		      orderTypeDetail += "  \"isShow\":0,";
     		    }
     		    orderTypeDetail += "  \"isRequire\":0,";
     		  }
     		 if($('#start_default').is(':checked')){
	 			 orderTypeDetail += "\"isDefault\":1,";
	 		  }
     		  if($('#startPrompt').val().trim()!=null) {
     			orderTypeDetail += "  \"prompt\": \""+$('#startPrompt').val().trim()+"\",";
     		  }
     		  orderTypeDetail += "  \"seq\": 3";
     		  orderTypeDetail += " }";
     		}
   		if($('#startDetailed').val().trim()!=null){
   		  orderTypeDetail += ",{ ";
   		  orderTypeDetail += "  \"name\": \""+$('#startDetailed').val().trim()+"\",";
   		  if($('#startDetailed_required').is(':checked')){
   			orderTypeDetail += "  \"isShow\":1,";
   		    orderTypeDetail += "  \"isRequire\":1,";
   		  } else {
   		    if($('#startDetailed_show').is(':checked')){
   			  orderTypeDetail += "  \"isShow\":1,";
   		    } else {
   		      orderTypeDetail += "  \"isShow\":0,";
   		    }
   		    orderTypeDetail += "  \"isRequire\":0,";
   		  }
   		  if($('#startDetailedPrompt').val().trim()!=null) {
   			orderTypeDetail += "  \"prompt\": \""+$('#startDetailedPrompt').val().trim()+"\",";
   		  }
   		  orderTypeDetail += "  \"seq\": 4";
   		  orderTypeDetail += " }";
   		}
   		
   		if($('#end').val().trim()!=null){
     		  orderTypeDetail += ",{ ";
     		  orderTypeDetail += "  \"name\": \""+$('#end').val().trim()+"\",";
     		  if($('#end_required').is(':checked')){
     			orderTypeDetail += "  \"isShow\":1,";
     		    orderTypeDetail += "  \"isRequire\":1,";
     		  } else {
     		    if($('#end_show').is(':checked')){
     			  orderTypeDetail += "  \"isShow\":1,";
     		    } else {
     		      orderTypeDetail += "  \"isShow\":0,";
     		    }
     		    orderTypeDetail += "  \"isRequire\":0,";
     		  }
     		 if($('#end_default').is(':checked')){
	 			 orderTypeDetail += "\"isDefault\":1,";
	 		  }
     		  if($('#endPrompt').val().trim()!=null) {
     			orderTypeDetail += "  \"prompt\": \""+$('#endPrompt').val().trim()+"\",";
     		  }
     		  orderTypeDetail += "  \"seq\": 5";
     		  orderTypeDetail += " }";
     	}

   		if($('#endDetailed').val().trim()!=null){
   		  orderTypeDetail += ",{ ";
   		  orderTypeDetail += "  \"name\": \""+$('#endDetailed').val().trim()+"\",";
   		  if($('#endDetailed_required').is(':checked')){
   			orderTypeDetail += "  \"isShow\":1,";
   		    orderTypeDetail += "  \"isRequire\":1,";
   		  } else {
   		    if($('#endDetailed_show').is(':checked')){
   			  orderTypeDetail += "  \"isShow\":1,";
   		    } else {
   		      orderTypeDetail += "  \"isShow\":0,";
   		    }
   		    orderTypeDetail += "  \"isRequire\":0,";
   		  }
   		  if($('#endDetailedPrompt').val().trim()!=null) {
   			orderTypeDetail += "  \"prompt\": \""+$('#endDetailedPrompt').val().trim()+"\",";
   		  }
   		  orderTypeDetail += "  \"seq\": 6";
   		  orderTypeDetail += " }";
   		}
   		if($('#recipients').val().trim()!=null){
     		  orderTypeDetail += ",{ ";
     		  orderTypeDetail += "  \"name\": \""+$('#recipients').val().trim()+"\",";
     		  if($('#recipients_required').is(':checked')){
     			orderTypeDetail += "  \"isShow\":1,";
     		    orderTypeDetail += "  \"isRequire\":1,";
     		  } else {
     		    if($('#recipients_show').is(':checked')){
     			  orderTypeDetail += "  \"isShow\":1,";
     		    } else {
     		      orderTypeDetail += "  \"isShow\":0,";
     		    }
     		    orderTypeDetail += "  \"isRequire\":0,";
     		  }
     		 if($('#recipients_default').is(':checked')){
	 			 orderTypeDetail += "\"isDefault\":1,";
	 		  }
     		  if($('#recipientsPrompt').val().trim()!=null) {
     			orderTypeDetail += "  \"prompt\": \""+$('#recipientsPrompt').val().trim()+"\",";
     		  }
     		  orderTypeDetail += "  \"seq\": 7";
     		  orderTypeDetail += " }";
     		}
   		if($('#phone').val().trim()!=null){
   		  orderTypeDetail += ",{ ";
   		  orderTypeDetail += "  \"name\": \""+$('#phone').val().trim()+"\",";
   		  if($('#phone_required').is(':checked')){
   			orderTypeDetail += "  \"isShow\":1,";
   		    orderTypeDetail += "  \"isRequire\":1,";
   		  } else {
   		    if($('#phone_show').is(':checked')){
   			  orderTypeDetail += "  \"isShow\":1,";
   		    } else {
   		      orderTypeDetail += "  \"isShow\":0,";
   		    }
   		    orderTypeDetail += "  \"isRequire\":0,";
   		  }
   		 if($('#phone_default').is(':checked')){
 			 orderTypeDetail += "\"isDefault\":1,";
 		  }
   		  if($('#phonePrompt').val().trim()!=null) {
   			orderTypeDetail += "  \"prompt\": \""+$('#phonePrompt').val().trim()+"\",";
   		  }
   		  orderTypeDetail += "  \"seq\": 8";
   		  orderTypeDetail += " }";
   		}
   		if($('#weight').val().trim()!=null){
     		  orderTypeDetail += ",{ ";
     		  orderTypeDetail += "  \"name\": \""+$('#weight').val().trim()+"\",";
     		  if($('#weight_required').is(':checked')){
     			orderTypeDetail += "  \"isShow\":1,";
     		    orderTypeDetail += "  \"isRequire\":1,";
     		  } else {
     		    if($('#weight_show').is(':checked')){
     			  orderTypeDetail += "  \"isShow\":1,";
     		    } else {
     		      orderTypeDetail += "  \"isShow\":0,";
     		    }
     		    orderTypeDetail += "  \"isRequire\":0,";
     		  }
     		  if($('#weightPrompt').val().trim()!=null) {
     			orderTypeDetail += "  \"prompt\": \""+$('#weightPrompt').val().trim()+"\",";
     		  }
     		  orderTypeDetail += "  \"seq\": 9";
     		  orderTypeDetail += " }";
     		}
   		if($('#goodsCash').val().trim()!=null){
   		  orderTypeDetail += ",{ ";
   		  orderTypeDetail += "  \"name\": \""+$('#goodsCash').val().trim()+"\",";
   		  if($('#goodsCash_required').is(':checked')){
   			orderTypeDetail += "  \"isShow\":1,";
   		    orderTypeDetail += "  \"isRequire\":1,";
   		  } else {
   		    if($('#goodsCash_show').is(':checked')){
   			  orderTypeDetail += "  \"isShow\":1,";
   		    } else {
   		      orderTypeDetail += "  \"isShow\":0,";
   		    }
   		    orderTypeDetail += "  \"isRequire\":0,";
   		  }
   		  if($('#goodsCashPrompt').val().trim()!=null) {
   			orderTypeDetail += "  \"prompt\": \""+$('#goodsCashPrompt').val().trim()+"\",";
   		  }
   		  orderTypeDetail += "  \"seq\": 10";
   		  orderTypeDetail += " }";
   		}
   		if($('#thanksCash').val().trim()!=null){
   		  orderTypeDetail += ",{ ";
   		  orderTypeDetail += "  \"name\": \""+$('#thanksCash').val().trim()+"\",";
   		  if($('#thanksCash_required').is(':checked')){
   			orderTypeDetail += "  \"isShow\":1,";
   		    orderTypeDetail += "  \"isRequire\":1,";
   		  } else {
   		    if($('#thanksCash_show').is(':checked')){
   			  orderTypeDetail += "  \"isShow\":1,";
   		    } else {
   		      orderTypeDetail += "  \"isShow\":0,";
   		    }
   		    orderTypeDetail += "  \"isRequire\":0,";
   		  }
   		  if($('#thanksCashPrompt').val().trim()!=null) {
   			orderTypeDetail += "  \"prompt\": \""+$('#thanksCashPrompt').val().trim()+"\",";
   		  }
   		  orderTypeDetail += "  \"seq\": 11";
   		  orderTypeDetail += " }";
   		}
   		if($('#protectPrice').val().trim()!=null){
     		  orderTypeDetail += ",{ ";
     		  orderTypeDetail += "  \"name\": \""+$('#protectPrice').val().trim()+"\",";
     		  if($('#protectPrice_required').is(':checked')){
     			orderTypeDetail += "  \"isShow\":1,";
     		    orderTypeDetail += "  \"isRequire\":1,";
     		  } else {
     		    if($('#protectPrice_show').is(':checked')){
     			  orderTypeDetail += "  \"isShow\":1,";
     		    } else {
     		      orderTypeDetail += "  \"isShow\":0,";
     		    }
     		    orderTypeDetail += "  \"isRequire\":0,";
     		  }
     		  if($('#protectPricePrompt').val().trim()!=null) {
     			orderTypeDetail += "  \"prompt\": \""+$('#protectPricePrompt').val().trim()+"\",";
     		  }
     		  orderTypeDetail += "  \"seq\": 12";
     		  orderTypeDetail += " }";
     		}
   		if($('#picture').val().trim()!=null){
     		  orderTypeDetail += ",{ ";
     		  orderTypeDetail += "  \"name\": \""+$('#picture').val().trim()+"\",";
     		  if($('#picture_required').is(':checked')){
     			orderTypeDetail += "  \"isShow\":1,";
     		    orderTypeDetail += "  \"isRequire\":1,";
     		  } else {
     		    if($('#picture_show').is(':checked')){
     			  orderTypeDetail += "  \"isShow\":1,";
     		    } else {
     		      orderTypeDetail += "  \"isShow\":0,";
     		    }
     		    orderTypeDetail += "  \"isRequire\":0,";
     		  }
     		  if($('#picturePrompt').val().trim()!=null) {
     			orderTypeDetail += "  \"prompt\": \""+$('#picturePrompt').val().trim()+"\",";
     		  }
     		  orderTypeDetail += "  \"seq\": 13";
     		  orderTypeDetail += " }";
     		}
   		if($('#content').val().trim()!=null){
   		  orderTypeDetail += ",{ ";
   		  orderTypeDetail += "  \"name\": \""+$('#content').val().trim()+"\",";
   		  if($('#content_required').is(':checked')){
   			orderTypeDetail += "  \"isShow\":1,";
   		    orderTypeDetail += "  \"isRequire\":1,";
   		  } else {
   		    if($('#content_show').is(':checked')){
   			  orderTypeDetail += "  \"isShow\":1,";
   		    } else {
   		      orderTypeDetail += "  \"isShow\":0,";
   		    }
   		    orderTypeDetail += "  \"isRequire\":0,";
   		  }
   		  if($('#contentPrompt').val().trim()!=null) {
   			orderTypeDetail += "  \"prompt\": \""+$('#contentPrompt').val().trim()+"\",";
   		  }
   		  orderTypeDetail += "  \"seq\": 14";
   		  orderTypeDetail += " }";
   		}
   		if($('#addServices').val().trim()!=null){
     		  orderTypeDetail += ",{ ";
     		  orderTypeDetail += "  \"name\": \""+$('#addServices').val().trim()+"\",";
     		  if($('#addServices_required').is(':checked')){
     			orderTypeDetail += "  \"isShow\":1,";
     		    orderTypeDetail += "  \"isRequire\":1,";
     		  } else {
     		    if($('#addServices_show').is(':checked')){
     			  orderTypeDetail += "  \"isShow\":1,";
     		    } else {
     		      orderTypeDetail += "  \"isShow\":0,";
     		    }
     		    orderTypeDetail += "  \"isRequire\":0,";
     		  }
     		  if($('#addServicesPrompt').val().trim()!=null) {
     			orderTypeDetail += "  \"prompt\": \""+$('#addServicesPrompt').val().trim()+"\",";
     		  }
     		  orderTypeDetail += "  \"seq\": 15";
     		  orderTypeDetail += " }";
     		}
   		
   		orderTypeDetail += "]";
   		var allowTips;
   		if($('#allowTips').is(':checked')){
   			allowTips = 1;
   		}else{
   			allowTips = 0;
   		}
		$.post(ctx+'/errand/up/createOrderType',
		{'typeName':$('#typeName').val(),'typeSeq':$("#typeSeq").val(),'errandOrderTypeDetaileds':orderTypeDetail,
		'typepicture':typepicture,'otherServices':JSON.stringify(otherService),
		'tips':JSON.stringify(tips),'allowTips':allowTips},
		function(data){
           if(data.success){
        	   $('#dialog_modifyCash').modal("hide");
                $.scojs_message(data.message, $.scojs_message.TYPE_OK);
                setTimeout(function(){
					window.location.reload(true);
				}, 1000);
	       }else{
                $.scojs_message(data.message, $.scojs_message.TYPE_ERROR);
	       }
	    },'json');
});
//删除类型
var thisButton;
$(document).on("click",".delete",function(){
      thisButton = $(this);
      var confirm = $.scojs_confirm({
        content: "你真的要删除该类型吗？",
        action:deleteType
      });
      confirm.show();
});
function deleteType() {
    $.post(ctx+'/errand/up/deleteOrderType',{'typeId':thisButton.attr("typeId"),'typeName':thisButton.attr("typeName")},function(data){
            if(data.success){
                $.scojs_message(data.message, $.scojs_message.TYPE_OK);
                setTimeout(function(){
						window.location.reload(true);
				}, 1000);
            }else{
                $.scojs_message(data.message, $.scojs_message.TYPE_ERROR);
                 setTimeout(function(){
						window.location.reload(true);
				}, 2000);
            }
    },'json');
}
$(document).on("click","#buyNeeds_required_update",function(){
	if($('#buyNeeds_required_update').is(':checked')){
		$('#buyNeeds_show_update').prop('checked','checked');
		$('#buyNeeds_show_update').prop('disabled',true);
	}
	else {
		$('#buyNeeds_show_update').prop('disabled',false);
	}
});
$(document).on("click","#startTime_required_update",function(){
	if($('#startTime_required_update').is(':checked')){
		$('#startTime_show_update').prop('checked','checked');
		$('#startTime_show_update').prop('disabled',true);
	}
	else {
		$('#startTime_show_update').prop('disabled',false);
	}
});
$(document).on("click","#start_required_update",function(){
	if($('#start_required_update').is(':checked')){
		$('#start_show_update').prop('checked','checked');
		$('#start_show_update').prop('disabled',true);
	}
	else {
		$('#start_show_update').prop('disabled',false);
	}
});
$(document).on("click","#startDetailed_required_update",function(){
	if($('#startDetailed_required_update').is(':checked')){
		$('#startDetailed_show_update').prop('checked','checked');
		$('#startDetailed_show_update').prop('disabled',true);
		$('#start_show_update').prop('checked','checked');
		$('#start_show_update').prop('disabled',true);
		$('#start_required_update').prop('checked','checked');
		$('#start_required_update').prop('disabled',true);
	}
	else {
		$('#startDetailed_show_update').prop('disabled',false);
	}
});
$(document).on("click","#end_required_update",function(){
	if($('#end_required_update').is(':checked')){
		$('#end_show_update').prop('checked','checked');
		$('#end_show_update').prop('disabled',true);
	}
	else {
		$('#end_show_update').prop('disabled',false);
	}
});
$(document).on("click","#endDetailed_required_update",function(){
	if($('#endDetailed_required_update').is(':checked')){
		$('#endDetailed_show_update').prop('checked','checked');
		$('#endDetailed_show_update').prop('disabled',true);
		$('#end_show_update').prop('checked','checked');
		$('#end_show_update').prop('disabled',true);
		$('#end_required_update').prop('checked','checked');
		$('#end_required_update').prop('disabled',true);
	}
	else {
		$('#endDetailed_show_update').prop('disabled',false);
		$('#end_required_update').prop('disabled',false);
	}
});
$(document).on("click","#protectPrice_required_update",function(){
	if($('#protectPrice_required_update').is(':checked')){
		$('#protectPrice_show_update').prop('checked','checked');
		$('#protectPrice_show_update').prop('disabled',true);
	}
	else {
		$('#protectPrice_show_update').prop('disabled',false);
	}
});
$(document).on("click","#recipients_required_update",function(){
	if($('#recipients_required_update').is(':checked')){
		$('#recipients_show_update').prop('checked','checked');
		$('#recipients_show_update').prop('disabled',true);
	}
	else {
		$('#recipients_show_update').prop('disabled',false);
	}
});
$(document).on("click","#phone_required_update",function(){
	if($('#phone_required_update').is(':checked')){
		$('#phone_show_update').prop('checked','checked');
		$('#phone_show_update').prop('disabled',true);
	}
	else {
		$('#phone_show_update').prop('disabled',false);
	}
});
$(document).on("click","#weight_required_update",function(){
	if($('#weight_required_update').is(':checked')){
		$('#weight_show_update').prop('checked','checked');
		$('#weight_show_update').prop('disabled',true);
	}
	else {
		$('#weight_show_update').prop('disabled',false);
	}
});
$(document).on("click","#goodsCash_required_update",function(){
	if($('#goodsCash_required_update').is(':checked')){
		$('#goodsCash_show_update').prop('checked','checked');
		$('#goodsCash_show_update').prop('disabled',true);
	}
	else {
		$('#goodsCash_show_update').prop('disabled',false);
	}
});
$(document).on("click","#thanksCash_required_update",function(){
	if($('#thanksCash_required_update').is(':checked')){
		$('#thanksCash_show_update').prop('checked','checked');
		$('#thanksCash_show_update').prop('disabled',true);
	}
	else {
		$('#thanksCash_show_update').prop('disabled',false);
	}
});
$(document).on("click","#picture_required_update",function(){
	if($('#picture_required_update').is(':checked')){
		$('#picture_show_update').prop('checked','checked');
		$('#picture_show_update').prop('disabled',true);
	}
	else {
		$('#picture_show_update').prop('disabled',false);
	}
});
$(document).on("click","#content_required_update",function(){
	if($('#content_required_update').is(':checked')){
		$('#content_show_update').prop('checked','checked');
		$('#content_show_update').prop('disabled',true);
	}
	else {
		$('#content_show_update').prop('disabled',false);
	}
});
$(document).on("click","#addServices_required_update",function(){
	if($('#addServices_required_update').is(':checked')){
		$('#addServices_show_update').prop('checked','checked');
		$('#addServices_show_update').prop('disabled',true);
	}
	else {
		$('#addServices_show_update').prop('disabled',false);
	}
});
//修改跑腿类型
	$(document).on("click",".update",function(){
		var typeId = $(this).attr("typeId");
	  	var typeName=$(this).attr("typeName");
	  	var typeSeq=$(this).attr("typeSeq");
	  	$("#typeId").val(typeId);
	  	 $("#typeName_update").val(typeName);
	  	$("#typeSeq_update").val(typeSeq);
	  	 $("[name = buyNeeds_show_update]:checkbox").prop("checked", false); 
	  	 $("[name = buyNeeds_required_update]:checkbox").prop("checked", false);
    	 $('#buyNeeds_show_update').prop('disabled',false);
    	 $("[name = startTime_show_update]:checkbox").prop("checked", false);
    	 $("[name = startTime_required_update]:checkbox").prop("checked", false);
  	     $('#startTime_show_update').prop('disabled',false);
  	     $("[name = addServices_required_update]:checkbox").prop("checked", false); 
		 $('#addServices_show_update').prop('disabled',false);
		 $("[name = addServices_show_update]:checkbox").prop("checked", false);
		 $("[name = content_required_update]:checkbox").prop("checked", false); 
		 $('#content_show_update').prop('disabled',false);
		 $("[name = content_show_update]:checkbox").prop("checked", false); 
		 $("[name = picture_required_update]:checkbox").prop("checked", false); 
		 $('#picture_show_update').prop('disabled',false);
		 $("[name = picture_show_update]:checkbox").prop("checked", false);
		 $("[name = thanksCash_required_update]:checkbox").prop("checked", false); 
		 $('#thanksCash_show_update').prop('disabled',false);
		 $("[name = thanksCash_show_update]:checkbox").prop("checked", false);
		 $("[name = goodsCash_required_update]:checkbox").prop("checked", false); 
		 $('#goodsCash_show_update').prop('disabled',false);
		 $("[name = goodsCash_show_update]:checkbox").prop("checked", false); 
		 $("[name = protectPrice_required_update]:checkbox").prop("checked", false); 
		 $('#protectPrice_show_update').prop('disabled',false);
		 $("[name = protectPrice_show_update]:checkbox").prop("checked", false);
		 $("[name = weight_required_update]:checkbox").prop("checked", false); 
		 $('#weight_show_update').prop('disabled',false);
		 $("[name = weight_show_update]:checkbox").prop("checked", false);
		 $("[name = start_show_update]:checkbox").prop("checked", false);
		 $("[name = start_required_update]:checkbox").prop("checked", false); 
		 $("[name = start_default_update]:checkbox").prop("checked", false); 
		 $('#start_show_update').prop('disabled',false);
		 $("[name = startDetailed_show_update]:checkbox").prop("checked", false);
		 $("[name = startDetailed_required_update]:checkbox").prop("checked", false); 
		 $('#startDetailed_show_update').prop('disabled',false);
		 $("[name = end_show_update]:checkbox").prop("checked", false);  
	     $("[name = end_required_update]:checkbox").prop("checked", false); 
	     $("[name = end_default_update]:checkbox").prop("checked", false); 
		 $('#end_show_update').prop('disabled',false);  
	     $("[name = endDetailed_show_update]:checkbox").prop("checked", false); 
		 $("[name = endDetailed_required_update]:checkbox").prop("checked", false);
		 $('#endDetailed_show_update').prop('disabled',false);
		 $("[name = recipients_show_update]:checkbox").prop("checked", false);
		 $("[name = recipients_required_update]:checkbox").prop("checked", false);
		 $("[name = recipients_default_update]:checkbox").prop("checked", false);
		 $('#recipients_show_update').prop('disabled',false);
		 $("[name = phone_show_update]:checkbox").prop("checked", false); 
		 $("[name = phone_required_update]:checkbox").prop("checked", false); 
		 $("[name = phone_default_update]:checkbox").prop("checked", false); 
		 $('#phone_show_update').prop('disabled',false);
	  	$.ajax({
	        url : ctx+'/errand/up/findOrderType',
	        type:'GET',
	        async:false,
	        dataType : 'json',
	        data : {
	        	"id":typeId
	        },
	        success : function(result){
	          var detail = [];
	          detail = result.data.errandOrderTypeDetaileds;
	          $("#buyNeeds_id").val(detail[0].id);
	          $("#buyNeeds_update").val(detail[0].name);
	          if(detail[0].isShow == 1) {
	              $("[name = buyNeeds_show_update]:checkbox").prop("checked", true);
	          }
	          if(detail[0].isRequire == 1) {
		            $("[name = buyNeeds_required_update]:checkbox").prop("checked", true);
		            $('#buyNeeds_show_update').prop('disabled',true);
		          }
	          
	          $("#buyNeedsPrompt_update").val(detail[0].prompt);
	          
	          $("#startTime_id").val(detail[1].id);
	          $("#startTime_update").val(detail[1].name);
	          if(detail[1].isShow == 1) {
	            $("[name = startTime_show_update]:checkbox").prop("checked", true);
	          }
	          if(detail[1].isRequire == 1) {
		              $("[name = startTime_required_update]:checkbox").prop("checked", true);
		              $('#startTime_show_update').prop('disabled',true);
		      }
	          $("#appointmentPrompt_update").val(detail[1].prompt);
	          
	          $("#start_id").val(detail[2].id);
	          $("#start_update").val(detail[2].name);
	          if(detail[2].isShow == 1) {
	            $("[name = start_show_update]:checkbox").prop("checked", true);
	          }
	          if(detail[2].isRequire == 1) {
		            $("[name = start_required_update]:checkbox").prop("checked", true);
		           // $('#start_show_update').prop('disabled',true);
		           // $('#start_required_update').prop('disabled',true);
		          }
	          if(detail[2].isDefault == 1){
	        	  $("[name = start_default_update]:checkbox").prop("checked", true);
	          }
	          $("#startPrompt_update").val(detail[2].prompt);
	          
	          
	          $("#startDetailed_id").val(detail[3].id);
	          $("#startDetailed_update").val(detail[3].name);
	          if(detail[3].isShow == 1) {
	            $("[name = startDetailed_show_update]:checkbox").prop("checked", true);
	          }
	          if(detail[3].isRequire == 1) {
		            $("[name = startDetailed_required_update]:checkbox").prop("checked", true);
		            $('#startDetailed_show_update').prop('disabled',true);
		          }
	          $("#startDetailedPrompt_update").val(detail[3].prompt);
	          
	          $("#end_id").val(detail[4].id);
	          $("#end_update").val(detail[4].name);
	          if(detail[4].isShow == 1) {
	            $("[name = end_show_update]:checkbox").prop("checked", true);
	          }
	          if(detail[4].isRequire == 1) {
		            $("[name = end_required_update]:checkbox").prop("checked", true);
		            $('#end_show_update').prop('disabled',true);
		          }
	          if(detail[4].isDefault == 1){
	        	  $("[name = end_default_update]:checkbox").prop("checked", true);
	          }
	          $("#endPrompt_update").val(detail[4].prompt);
	          
	          $("#endDetailed_id").val(detail[5].id);
	          $("#endDetailed_update").val(detail[5].name);
	          if(detail[5].isShow == 1) {
	            $("[name = endDetailed_show_update]:checkbox").prop("checked", true);
	          }
	          if(detail[5].isRequire == 1) {
		            $("[name = endDetailed_required_update]:checkbox").prop("checked", true);
		            $('#endDetailed_show_update').prop('disabled',true);
		          }
	          $("#endDetailedPrompt_update").val(detail[5].prompt);
	          
	          $("#recipients_id").val(detail[6].id);
	          $("#recipients_update").val(detail[6].name);
	          if(detail[6].isShow == 1) {
	            $("[name = recipients_show_update]:checkbox").prop("checked", true);
	          }
	          if(detail[6].isRequire == 1) {
		            $("[name = recipients_required_update]:checkbox").prop("checked", true);
		            $('#recipients_show_update').prop('disabled',true);
		          }
	          if(detail[6].isDefault == 1){
	        	  $("[name = recipients_default_update]:checkbox").prop("checked", true);
	          }
	          $("#recipientsPrompt_update").val(detail[6].prompt);
	          
              $("#phone_id").val(detail[7].id);
		       $("#phone_update").val(detail[7].name);
		       if(detail[7].isShow == 1) {
		         $("[name = phone_show_update]:checkbox").prop("checked", true);
		       }
		       if(detail[7].isRequire == 1) {
			     $("[name = phone_required_update]:checkbox").prop("checked", true);
			     $('#phone_show_update').prop('disabled',true);
		       }
		       if(detail[7].isDefault == 1){
		        	 $("[name = phone_default_update]:checkbox").prop("checked", true);
		         }
		       $("#phonePrompt_update").val(detail[7].prompt);
		       
		       $("#weight_id").val(detail[8].id);
		       $("#weight_update").val(detail[8].name);
		       if(detail[8].isShow == 1) {
		         $("[name = weight_show_update]:checkbox").prop("checked", true);
		       }
		       if(detail[8].isRequire == 1) {
			     $("[name = weight_required_update]:checkbox").prop("checked", true);
			     $('#weight_show_update').prop('disabled',true);
		       }
		       $("#weightPrompt_update").val(detail[8].prompt);
		       
		       $("#goodsCash_id").val(detail[9].id);
		       $("#goodsCash_update").val(detail[9].name);
		       if(detail[9].isShow == 1) {
		         $("[name = goodsCash_show_update]:checkbox").prop("checked", true);
		       }
		       if(detail[9].isRequire == 1) {
			     $("[name = goodsCash_required_update]:checkbox").prop("checked", true);
			     $('#goodsCash_show_update').prop('disabled',true);
		          }
		       $("#goodsCashPrompt_update").val(detail[9].prompt);
		       
		       $("#thanksCash_id").val(detail[10].id);
		       $("#thanksCash_update").val(detail[10].name);
		       if(detail[10].isShow == 1) {
		         $("[name = thanksCash_show_update]:checkbox").prop("checked", true);
		          }
		       if(detail[10].isRequire == 1) {
			     $("[name = thanksCash_required_update]:checkbox").prop("checked", true);
			     $('#thanksCash_show_update').prop('disabled',true);
		       }
		       $("#thanksCashPrompt_update").val(detail[10].prompt);
		       
		       $("#protectPrice_id").val(detail[11].id);
		       $("#protectPrice_update").val(detail[11].name);
		       if(detail[11].isShow == 1) {
		         $("[name = protectPrice_show_update]:checkbox").prop("checked", true);
		          }
		       if(detail[11].isRequire == 1) {
			     $("[name = protectPrice_required_update]:checkbox").prop("checked", true);
			     $('#protectPrice_show_update').prop('disabled',true);
		       }
		       $("#protectPricePrompt_update").val(detail[11].prompt);
		       
		       
		       $("#picture_id").val(detail[12].id);
		       $("#picture_update").val(detail[12].name);
		       if(detail[12].isShow == 1) {
		         $("[name = picture_show_update]:checkbox").prop("checked", true);
		       }
		       if(detail[12].isRequire == 1) {
			     $("[name = picture_required_update]:checkbox").prop("checked", true);
			     $('#picture_show_update').prop('disabled',true);
		          }
		       $("#picturePrompt_update").val(detail[12].prompt);
		       
		       $("#content_id").val(detail[13].id);
		       $("#content_update").val(detail[13].name);
		       if(detail[13].isShow == 1) {
		         $("[name = content_show_update]:checkbox").prop("checked", true);
		       }
		       if(detail[13].isRequire == 1) {
			     $("[name = content_required_update]:checkbox").prop("checked", true);
			     $('#content_show_update').prop('disabled',true);
		       }
		       $("#contentPrompt_update").val(detail[13].prompt);
		       
		       $("#addServices_id").val(detail[14].id);
		       $("#addServices_update").val(detail[14].name);
		       if(detail[14].isShow == 1) {
		         $("[name = addServices_show_update]:checkbox").prop("checked", true);
		       }
		       if(detail[14].isRequire == 1) {
			     $("[name = addServices_required_update]:checkbox").prop("checked", true);
			     $('#addServices_show_update').prop('disabled',true);
		       }
		       $("#addServicesPrompt_update").val(detail[14].prompt);
		       //附加服务信息
		       $("#otherService_update").html("");
		        updateOtherService = result.data.otherServices;
		        f=0;
		        n=0;
		        if(updateOtherService.length>0){
		        	for(var a=0;a<updateOtherService.length;a++){
		        		$("#otherService_update").append("<div id='"+updateOtherService[a].otherServices+"' style='float:left;margin-left:10px'><table><tr><td><div id='"+updateOtherService[a].otherServices+"''>" 
		    			+ updateOtherService[a].otherServices + "</div></td></tr><tr><td style='text-align:center;'><a href='javascript:updelBotton(\"" + updateOtherService[a].otherServices +"\");'>删除</a></td></tr></table></div>");
		        		f++;
		        	}
		        }
		        $('#updateTips').html("");
		        var th = "<tr><th style='text-align:center;'>标签名称</th><th style='text-align:center;'>标签图标</th>"
					+ "<th style='text-align:center;width:150px;'>是否在地图中检索 </th><th style='text-align:center;width:150px;'>地图中检索名称</th>"
					+ "<th colspan='2' style='text-align:center;'>操作</th></tr>";
		        $('#updateTips').append(th);
		        updatetips = result.data.tips;
		        if(updatetips.length>0){
		        	for (var b= 0;b<updatetips.length;b++) {
		        		if(updatetips[b].ifCheck == 0){
		        			$('#updateTips').append("<tr id='updatetips" + b + "'><td style='text-align:center;'><input id='tipName"+n+"' type='hidden' value='"+updatetips[b].tipName+"'/>"+ updatetips[b].tipName 
			        				+ "</td><td style='text-align:center;'><input id='tipspicture"+n+"' type='hidden' value='"+updatetips[b].tipspicture+"'/><img src='"+ctx+ updatetips[b].tipspicture
			        				+"' style='width:40px;height:40px;vertical-align:middle;'/>"  
			        				+ "</td><td style='text-align:center;'><input id='ifCheck"+n+"' type='hidden' value='0'/>否"
			        				+ "</td><td style='text-align:center;'><input id='tipQueryName"+n+"' type='hidden' value='"+ updatetips[b].tipQueryName +"'/>" + updatetips[b].tipQueryName
			        				+ "</td><td style='text-align:center;'><a href='javascript:updateTips(\""
			        				+ updatetips[b].tipName+"\",\"" +updatetips[b].tipspicture + "\",\""+ updatetips[b].tipQueryName +"\",\""+ 0 +"\",\"updatetips"+n+"\");'>编辑 </a>"
			        				+ "</td><td style='text-align:center;'><a href='javascript:updeltr(\"updatetips" + n +"\");'>删除</a></td><tr>");
		        		}else{
		        			$('#updateTips').append("<tr id='updatetips" + b + "'><td style='text-align:center;'><input id='tipName"+n+"' type='hidden' value='"+updatetips[b].tipName+"'/>"+ updatetips[b].tipName 
			        				+ "</td><td style='text-align:center;'><input id='tipspicture"+n+"' type='hidden' value='"+updatetips[b].tipspicture+"'/><img src='"+ctx+ updatetips[b].tipspicture
			        				+"' style='width:40px;height:40px;vertical-align:middle;'/>"  
			        				+ "</td><td style='text-align:center;'><input id='ifCheck"+n+"' type='hidden' value='1'/>是"
			        				+ "</td><td style='text-align:center;'><input id='tipQueryName"+n+"' type='hidden' value='"+ updatetips[b].tipQueryName +"'/>" + updatetips[b].tipQueryName
			        				+ "</td><td style='text-align:center;'><a href='javascript:updateTips(\""
			        				+ updatetips[b].tipName+"\",\"" +updatetips[b].tipspicture + "\",\""+ updatetips[b].tipQueryName +"\",\""+ 1 +"\",\"updatetips"+n+"\");'>编辑 </a>"
			        				+ "</td><td style='text-align:center;'><a href='javascript:updeltr(\"updatetips" + b +"\");'>删除</a></td><tr>");
		        		}
		        		n++;
					}
		        }
		        if(result.data.allowTips == 1){
		        	$("[name = allowTips_update]:checkbox").prop("checked", true);
		        }else{
		        	$("[name = allowTips_update]:checkbox").prop("checked", false);
		        }
		        if(result.data.typepicture != null){
		        	typepicture_update=result.data.typepicture;
		        	var pictures=$(".typepicture_update");
		        	for(var i=0;i<pictures.length;i++){
		    			var p=pictures[i];
		    			if(typepicture_update==$(p).attr("src").replace(ctx,"")){
		    				$(p).parent().css("border","1px solid red");
		    			}else{
		    				$(p).parent().css("border","");
		    			}
		    		}
		        }
	        }
	     });
	  	 
		 $('#update_orderType').modal();
 });
	function delBotton(serviceName){
		$("#"+serviceName).remove();
		otherService.splice($.inArray(serviceName, otherService),1);
		i--;
	}
	function updelBotton(serviceName){
		$("#"+serviceName).remove();
		updateOtherService.splice($.inArray(serviceName, updateOtherService),1);
		f--;
	}
	function deltr(tipName){
		$("tr#"+tipName).remove();
		tips.splice($.inArray(tipName, tips),1);
		t--;
	}
	function updeltr(id){
		$("tr#"+id).remove();
	}
	$('#addOhterServices').on('click',function(){
//		if(otherService.length == 10){
//			$.scojs_message("最多只能添加10项附加服务！！", $.scojs_message.TYPE_ERROR);
//			return false;
//		}
		$('#otherServices').val("");
		$('#dialog_otherServises').modal();
		$('#dialog_modifyCash').modal("hide");
		$('#dialog_tips').modal("hide");
		
	});
	$('#addOhterServices_update').on('click',function(){
//		if(updateOtherService.length == 10){
//			$.scojs_message("最多只能添加10项附加服务！！", $.scojs_message.TYPE_ERROR);
//			return false;
//		}
		$('#otherServices_update').val("");
		$('#update_orderType').modal("hide");
		$('#dialog_otherServises_update').modal();
	});
	$('#updateservice').on('click',function(){
		var service = "{'otherServices':'"+$('#otherServices_update').val()+"'}";
		if($.trim($('#otherServices_update').val()).length==0){
			$.scojs_message("附加服务名称不能为空！！", $.scojs_message.TYPE_ERROR);
			return false;
		}
//		if(updateOtherService.length>0){
//			for (var int = 0; int < updateOtherService.length; int++) {
//				if(updateOtherService[int].addService == $('#otherServices_update').val()){
//					$.scojs_message("不能添加相同的附加服务！！", $.scojs_message.TYPE_ERROR);
//					return false;
//				}
//			}
//		}
		updateOtherService[f] = eval('(' + service + ')');
		$('#otherService_update').append("<div id='"+$('#otherServices_update').val()+"' style='float:left;margin-left:10px'><table><tr><td>" 
				+ $('#otherServices_update').val() + "</td></tr><tr><td style='text-align:center;'><a href='javascript:delBotton(\"" + $('#otherServices_update').val() +"\");'>删除</a></td></tr></table></div>");
		$('#dialog_otherServises_update').modal("hide");
		$('#update_orderType').modal();
		$('#update_orderType').css({"overflow-y":"auto"});
		f++;
	});
	$('#saveservice').on('click',function(){
		var service = "{'otherServices':'"+$('#otherServices').val()+"'}";
		if($.trim($('#otherServices').val()).length==0){
			$.scojs_message("附加服务名称不能为空！！", $.scojs_message.TYPE_ERROR);
			return false;
		}
		if(otherService.length>0){
			for (var int = 0; int < otherService.length; int++) {
				if(otherService[int].addService == $('#otherServices').val()){
					$.scojs_message("不能添加相同的附加服务！！", $.scojs_message.TYPE_ERROR);
					return false;
				}
			}
		}
		otherService[i] = eval('(' + service + ')');
		$('#otherService').append("<div id='"+$('#otherServices').val()+"' style='float:left;margin-left:10px'><table><tr><td><div id='"+$('#otherServices').val()+"'>" 
				+ $('#otherServices').val() + "</div></td></tr><tr><td style='text-align:center;'><a href='javascript:delBotton(\"" + $('#otherServices').val() +"\");'>删除</a></td></tr></table></div>");
		$('#dialog_otherServises').modal("hide");
		$('#dialog_modifyCash').modal();
		$('#dialog_modifyCash').css({"overflow-y":"auto"});
		
		i++;
	});
	$('#close_modal_service').on('click',function(){
		$('#dialog_otherServises').modal("hide");
		$('#dialog_modifyCash').modal();
		$('#dialog_modifyCash').css({"overflow-y":"auto"});
	});
	$('#addtips').on('click',function(){
//		if(tips.length == 10){
//			$.scojs_message("最多只能添加10个热门标签！！", $.scojs_message.TYPE_ERROR);
//			return false;
//		}
		var tipspictures=$(".tipspicture");
		for(var i=0;i<tipspictures.length;i++){
			var p=tipspictures[i];
			$(p).parent().css("border","");
		}
		$('#tipName').val("");
		$('#tipQueryName').val("");
		$("input[name = ifCheck]").eq(0).prop("checked",true);
		tipspicture = "";
		$('#dialog_tips').modal();
		$('#dialog_modifyCash').modal("hide");
		$('#dialog_otherServises').modal("hide");
	});
	$('#addtips_update').on('click',function(){
//		if(updatetips.length == 10){
//			$.scojs_message("最多只能添加10个热门标签！！", $.scojs_message.TYPE_ERROR);
//			return false;
//		}
		var tipspicture_update=$(".tipspicture_update");
		for(var i=0;i<tipspicture_update.length;i++){
			var p=tipspicture_update[i];
			$(p).parent().css("border","");
		}
		$('#tipName_update').val("");
		$('#tipName_old').val("");
		$('#tipQueryName_update').val("");
		tipspicture_update = "";
		$("input[name = ifCheck_update]").eq(0).prop("checked",true);
		$('#dialog_tips_update').modal();
		$('#update_orderType').modal("hide");
	});
	$('#savetips').on('click',function(){
		var tipName = $('#tipName').val();
		if(tipName == ""){
			$.scojs_message("热门标签名称不能为空！！", $.scojs_message.TYPE_ERROR);
			return false;
		}
//		if(tips.length>0){
//			for(var j=0;j<tips.length;j++){
//				if(tips[j].tipName == tipName){
//					$.scojs_message("不能添加相同名称的热门标签！！", $.scojs_message.TYPE_ERROR);
//					return false;
//				}
//			}
//		}
		var tipQueryName = $('#tipQueryName').val();
		var ifCheck = $("input[name='ifCheck']:checked").val();
		var jsonstr = "{'tipName':'"+tipName+"','tipspicture':'" + tipspicture + "','tipQueryName':'" 
			+ tipQueryName + "','ifCheck':'" + ifCheck +"'}";
		tips[t] = eval('(' + jsonstr + ')');
		if(ifCheck == 1){
			$('#Tips').append("<tr id='tipName" + t + "'><td style='text-align:center;'>"+ tipName 
					+ "</td><td style='text-align:center;'><img src='" + ctx + tipspicture
					+"' style='width:40px;height:40px;vertical-align:middle;'/>" 
					+ "</td><td style='text-align:center;'>是"
					+ "</td><td style='text-align:center;'>" + tipQueryName
					+ "</td><td style='text-align:center;'><a href='javascript:deltr(\"tipName" + t +"\");'>删除</a></td><tr>");
		}
		if(ifCheck == 0){
			$('#Tips').append("<tr id='tipName" + t + "'><td style='text-align:center;'>"+ tipName 
					+ "</td><td style='text-align:center;'><img src='" + ctx + tipspicture
					+"' style='width:40px;height:40px;vertical-align:middle;'/>"  
					+ "</td><td style='text-align:center;'>否"
					+ "</td><td style='text-align:center;'>" + tipQueryName
					+ "</td><td style='text-align:center;'><a href='javascript:deltr(\"tipName" + t +"\");'>删除</a></td><tr>");
		}
		t++;
		$('#dialog_tips').modal("hide");
		$('#dialog_modifyCash').modal();
		$('#dialog_modifyCash').css({"overflow-y":"auto"});
	});
	$('#updatetips').on('click',function(){
		var tipName = $('#tipName_update').val();
		if(tipName == ""){
			$.scojs_message("热门标签名称不能为空！！", $.scojs_message.TYPE_ERROR);
			return false;
		}
//		if($('#tipName_old').val()!=tipName){
//			for(var j=0;j<n;j++){
//				if($("#tipName"+j).val() == tipName){
//					$.scojs_message("该名称的热门标签已存在！！", $.scojs_message.TYPE_ERROR);
//					return false;
//				}
//			}
//		}
		if($('#tipName_old').val()!=null && $('#tipName_old').val()!=""){
			updeltr($('#tipName_old').val());
		}
		var tipQueryName = $('#tipQueryName_update').val();
		var ifCheck = $("input[name='ifCheck_update']:checked").val();
		var ifCheckStr="是";
		if(ifCheck == 0){
			ifCheckStr="否";
		}

		$('#updateTips').append("<tr id='updatetips" + n + "'><td style='text-align:center;'><input id='tipName"+n+"' type='hidden' value='"+tipName+"'/>"+ tipName 
				+ "</td><td style='text-align:center;'><input id='tipspicture"+n+"' type='hidden' value='"+tipspicture_update+"'/><img src='" + ctx + tipspicture_update
				+"' style='width:40px;height:40px;vertical-align:middle;'/>"  
				+ "</td><td style='text-align:center;'><input id='ifCheck"+n+"' type='hidden' value='"+ ifCheck +"'/>" + ifCheckStr
				+ "</td><td style='text-align:center;'><input id='tipQueryName"+n+"' type='hidden' value='"+ tipQueryName +"'/>" + tipQueryName
				+ "</td><td style='text-align:center;'><a href='javascript:updateTips(\""
				+ tipName+"\",\"" +tipspicture_update + "\",\""+ tipQueryName +"\",\""+ ifCheck +"\",\"updatetips"+n+"\");'>编辑 </a>"
				+ "</td><td style='text-align:center;'><a href='javascript:updeltr(\"updatetips" + n +"\");'>删除</a></td><tr>");

		n++;
		
		$('#dialog_tips_update').modal("hide");
		$('#update_orderType').modal();
		$('#update_orderType').css({"overflow-y":"auto"});
	});
	$('#close_modal_tips').on('click',function(){
		$('#dialog_tips').modal("hide");
		$('#dialog_modifyCash').modal();
		$('#dialog_modifyCash').css({"overflow-y":"auto"});
	});
	function updateTips(tipName,tipspicture,tipQueryName,ifCheck,id){
		$("#tipName_update").val(tipName);
		$("#tipName_old").val(id);
		$("#tipQueryName_update").val(tipQueryName);
		tipspicture_update = tipspicture;
		if(tipspicture_update != null){
	    	var pictures=$(".tipspicture_update");
	    	for(var i=0;i<pictures.length;i++){
				var p=pictures[i];
				if(tipspicture_update==$(p).attr("src").replace(ctx,"")){
					$(p).parent().css("border","1px solid red");
				}else{
					$(p).parent().css("border","");
				}
			}
	    }
		$("input[name = ifCheck_update]").prop("checked",false);
		if(ifCheck == 1){
			$("input[name = ifCheck_update]").eq(0).prop("checked",true);
		}
		if(ifCheck == 0){
			$("input[name = ifCheck_update]").eq(1).prop("checked",true);
		}
		$('#update_orderType').modal("hide");
		$('#dialog_tips_update').modal();
	}
	$("#close_modal_tips_update").on("click",function(){
		$('#dialog_tips_update').modal("hide");
		$('#update_orderType').modal();
		$('#update_orderType').css({"overflow-y":"auto"});
	});
	
 $(document).on("click","#save_update",function(){
 	if($("#typeName_update").val()==null || $('#typeName_update').val().trim()==""){
		$.scojs_message("请填写名称", $.scojs_message.TYPE_ERROR);
		return false;
 	}
 	if($("#typeSeq_update").val()==null || $('#typeSeq_update').val().trim()==""){
		$.scojs_message("请填写显示顺序", $.scojs_message.TYPE_ERROR);
		return false;
 	}
 	if(!$('#start_required_update').is(':checked') && !$('#end_required_update').is(':checked')){
			$.scojs_message("起点和终点必须选择一个必填", $.scojs_message.TYPE_ERROR);
 		return false;
		}
// 	if($("#areaId_update").val()==null){
//		$.scojs_message("请选择收费", $.scojs_message.TYPE_ERROR);
//		return false;
// 	}
// 	if(isMainCompany){
// 		if($("#companyId_update").val()==null || $("#companyId_update").val()==""){
// 			$.scojs_message("请选择公司", $.scojs_message.TYPE_ERROR);
// 			return false;
// 		}
// 	}
	
 	
 	var orderTypeDetail =" [ "
			if($('#buyNeeds_update').val().trim()!=null){
	   		  orderTypeDetail += "{ ";
	   		  orderTypeDetail += "\"id\":"+$('#buyNeeds_id').val().trim() + ",\"name\": \""+$('#buyNeeds_update').val().trim()+"\",";
	   		  if($('#buyNeeds_required_update').is(':checked')){
	   			orderTypeDetail += "  \"isShow\":1,";
	   		    orderTypeDetail += "  \"isRequire\":1,";
	   		  } else {
	   		    if($('#buyNeeds_show_update').is(':checked')){
	   			  orderTypeDetail += "  \"isShow\":1,";
	   		    } else {
	   		      orderTypeDetail += "  \"isShow\":0,";
	   		    }
	   		    orderTypeDetail += "  \"isRequire\":0,";
	   		  }
	   		  if($('#buyNeedsPrompt_update').val().trim()!=null) {
	   			orderTypeDetail += "  \"prompt\": \""+$('#buyNeedsPrompt_update').val().trim()+"\",";
	   		  }
	   		  orderTypeDetail += "  \"seq\": 1";
	   		  orderTypeDetail += " }";
	   		}
		if($('#startTime_update').val().trim()!=null){
		  orderTypeDetail += ",{ ";
		  orderTypeDetail += "\"id\":"+$('#startTime_id').val().trim() + ",\"name\": \""+$('#startTime_update').val().trim()+"\",";
		  if($('#startTime_required_update').is(':checked')){
			orderTypeDetail += "  \"isShow\":1,";
		    orderTypeDetail += "  \"isRequire\":1,";
		  } else {
		    if($('#startTime_show_update').is(':checked')){
			  orderTypeDetail += "  \"isShow\":1,";
		    } else {
		      orderTypeDetail += "  \"isShow\":0,";
		    }
		    orderTypeDetail += "  \"isRequire\":0,";
		  }
		  if($('#appointmentPrompt_update').val().trim()!=null) {
			orderTypeDetail += "  \"prompt\": \""+$('#appointmentPrompt_update').val().trim()+"\",";
		  }
		  orderTypeDetail += "  \"seq\": 2";
		  orderTypeDetail += " }";
		  console.debug($('#startTime_update').val());
		}
		if($('#start_update').val().trim()!=null){
 		  orderTypeDetail += ",{ ";
 		  orderTypeDetail += " \"id\":"+$('#start_id').val().trim() + ",\"name\": \""+$('#start_update').val().trim()+"\",";
 		  if($('#start_required_update').is(':checked')){
 			orderTypeDetail += "  \"isShow\":1,";
 		    orderTypeDetail += "  \"isRequire\":1,";
 		  } else {
 		    if($('#start_show_update').is(':checked')){
 			  orderTypeDetail += "  \"isShow\":1,";
 		    } else {
 		      orderTypeDetail += "  \"isShow\":0,";
 		    }
 		    orderTypeDetail += "  \"isRequire\":0,";
 		  }
 		  if($('#start_default_update').is(':checked')){
 			 orderTypeDetail += "\"isDefault\":1,";
 		  }else{
 			 orderTypeDetail += "\"isDefault\":0,";
 		  }
 		  if($('#startPrompt_update').val().trim()!=null) {
 			orderTypeDetail += "  \"prompt\": \""+$('#startPrompt_update').val().trim()+"\",";
 		  }
 		  orderTypeDetail += "  \"seq\": 3";
 		  orderTypeDetail += " }";
 		}
		if($('#startDetailed_update').val().trim()!=null){
		  orderTypeDetail += ",{ ";
		  orderTypeDetail += " \"id\":"+$('#startDetailed_id').val().trim() + ",\"name\": \""+$('#startDetailed_update').val().trim()+"\",";
		  if($('#startDetailed_required_update').is(':checked')){
			orderTypeDetail += "  \"isShow\":1,";
		    orderTypeDetail += "  \"isRequire\":1,";
		  } else {
		    if($('#startDetailed_show_update').is(':checked')){
			  orderTypeDetail += "  \"isShow\":1,";
		    } else {
		      orderTypeDetail += "  \"isShow\":0,";
		    }
		    orderTypeDetail += "  \"isRequire\":0,";
		  }
		  if($('#startDetailedPrompt_update').val().trim()!=null) {
			orderTypeDetail += "  \"prompt\": \""+$('#startDetailedPrompt_update').val().trim()+"\",";
		  }
		  orderTypeDetail += "  \"seq\": 4";
		  orderTypeDetail += " }";
		}
		
		if($('#end_update').val().trim()!=null){
 		  orderTypeDetail += ",{ ";
 		  orderTypeDetail += " \"id\":"+$('#end_id').val().trim() + ",\"name\": \""+$('#end_update').val().trim()+"\",";
 		  if($('#end_required_update').is(':checked')){
 			orderTypeDetail += "  \"isShow\":1,";
 		    orderTypeDetail += "  \"isRequire\":1,";
 		  } else {
 		    if($('#end_show_update').is(':checked')){
 			  orderTypeDetail += "  \"isShow\":1,";
 		    } else {
 		      orderTypeDetail += "  \"isShow\":0,";
 		    }
 		    orderTypeDetail += "  \"isRequire\":0,";
 		  }
 		 if($('#end_default_update').is(':checked')){
 			 orderTypeDetail += "\"isDefault\":1,";
 		  }else{
 			 orderTypeDetail += "\"isDefault\":0,";
 		  }
 		  if($('#endPrompt_update').val().trim()!=null) {
 			orderTypeDetail += "  \"prompt\": \""+$('#endPrompt_update').val().trim()+"\",";
 		  }
 		  orderTypeDetail += "  \"seq\": 5";
 		  orderTypeDetail += " }";
 	}

		if($('#endDetailed_update').val().trim()!=null){
		  orderTypeDetail += ",{ ";
		  orderTypeDetail += " \"id\":"+$('#endDetailed_id').val().trim() + ",\"name\": \""+$('#endDetailed_update').val().trim()+"\",";
		  if($('#endDetailed_required_update').is(':checked')){
			orderTypeDetail += "  \"isShow\":1,";
		    orderTypeDetail += "  \"isRequire\":1,";
		  } else {
		    if($('#endDetailed_show_update').is(':checked')){
			  orderTypeDetail += "  \"isShow\":1,";
		    } else {
		      orderTypeDetail += "  \"isShow\":0,";
		    }
		    orderTypeDetail += "  \"isRequire\":0,";
		  }
		  if($('#endDetailedPrompt_update').val().trim()!=null) {
			orderTypeDetail += "  \"prompt\": \""+$('#endDetailedPrompt_update').val().trim()+"\",";
		  }
		  orderTypeDetail += "  \"seq\": 6";
		  orderTypeDetail += " }";
		}
		if($('#recipients_update').val().trim()!=null){
 		  orderTypeDetail += ",{ ";
 		  orderTypeDetail += " \"id\":"+$('#recipients_id').val().trim() + ",\"name\": \""+$('#recipients_update').val().trim()+"\",";
 		  if($('#recipients_required_update').is(':checked')){
 			orderTypeDetail += "  \"isShow\":1,";
 		    orderTypeDetail += "  \"isRequire\":1,";
 		  } else {
 		    if($('#recipients_show_update').is(':checked')){
 			  orderTypeDetail += "  \"isShow\":1,";
 		    } else {
 		      orderTypeDetail += "  \"isShow\":0,";
 		    }
 		    orderTypeDetail += "  \"isRequire\":0,";
 		  }
 		 if($('#recipients_default_update').is(':checked')){
 			 orderTypeDetail += "\"isDefault\":1,";
 		  }else{
 			 orderTypeDetail += "\"isDefault\":0,";
 		  }
 		  if($('#recipientsPrompt_update').val().trim()!=null) {
 			orderTypeDetail += "  \"prompt\": \""+$('#recipientsPrompt_update').val().trim()+"\",";
 		  }
 		  orderTypeDetail += "  \"seq\": 7";
 		  orderTypeDetail += " }";
 		}
		if($('#phone_update').val().trim()!=null){
		  orderTypeDetail += ",{ ";
		  orderTypeDetail += " \"id\":"+$('#phone_id').val().trim() + ",\"name\": \""+$('#phone_update').val().trim()+"\",";
		  if($('#phone_required_update').is(':checked')){
			orderTypeDetail += "  \"isShow\":1,";
		    orderTypeDetail += "  \"isRequire\":1,";
		  } else {
		    if($('#phone_show_update').is(':checked')){
			  orderTypeDetail += "  \"isShow\":1,";
		    } else {
		      orderTypeDetail += "  \"isShow\":0,";
		    }
		    orderTypeDetail += "  \"isRequire\":0,";
		  }
		  if($('#phone_default_update').is(':checked')){
	 			 orderTypeDetail += "\"isDefault\":1,";
	 		  }else{
	  			 orderTypeDetail += "\"isDefault\":0,";
	 		  }
		  if($('#phonePrompt_update').val().trim()!=null) {
			orderTypeDetail += "  \"prompt\": \""+$('#phonePrompt_update').val().trim()+"\",";
		  }
		  orderTypeDetail += "  \"seq\": 8";
		  orderTypeDetail += " }";
		}
		if($('#weight_update').val().trim()!=null){
 		  orderTypeDetail += ",{ ";
 		  orderTypeDetail += " \"id\":"+$('#weight_id').val().trim() + ",\"name\": \""+$('#weight_update').val().trim()+"\",";
 		  if($('#weight_required_update').is(':checked')){
 			orderTypeDetail += "  \"isShow\":1,";
 		    orderTypeDetail += "  \"isRequire\":1,";
 		  } else {
 		    if($('#weight_show_update').is(':checked')){
 			  orderTypeDetail += "  \"isShow\":1,";
 		    } else {
 		      orderTypeDetail += "  \"isShow\":0,";
 		    }
 		    orderTypeDetail += "  \"isRequire\":0,";
 		  }
 		  if($('#weightPrompt_update').val().trim()!=null) {
 			orderTypeDetail += "  \"prompt\": \""+$('#weightPrompt_update').val().trim()+"\",";
 		  }
 		  orderTypeDetail += "  \"seq\": 9";
 		  orderTypeDetail += " }";
 		}
		if($('#goodsCash_update').val().trim()!=null){
		  orderTypeDetail += ",{ ";
		  orderTypeDetail += " \"id\":"+$('#goodsCash_id').val().trim() + ",\"name\": \""+$('#goodsCash_update').val().trim()+"\",";
		  if($('#goodsCash_required_update').is(':checked')){
			orderTypeDetail += "  \"isShow\":1,";
		    orderTypeDetail += "  \"isRequire\":1,";
		  } else {
		    if($('#goodsCash_show_update').is(':checked')){
			  orderTypeDetail += "  \"isShow\":1,";
		    } else {
		      orderTypeDetail += "  \"isShow\":0,";
		    }
		    orderTypeDetail += "  \"isRequire\":0,";
		  }
		  if($('#goodsCashPrompt_update').val().trim()!=null) {
			orderTypeDetail += "  \"prompt\": \""+$('#goodsCashPrompt_update').val().trim()+"\",";
		  }
		  orderTypeDetail += "  \"seq\": 10";
		  orderTypeDetail += " }";
		}
		if($('#thanksCash_update').val().trim()!=null){
		  orderTypeDetail += ",{ ";
		  orderTypeDetail += " \"id\":"+$('#thanksCash_id').val().trim() + ",\"name\": \""+$('#thanksCash_update').val().trim()+"\",";
		  if($('#thanksCash_required_update').is(':checked')){
			orderTypeDetail += "  \"isShow\":1,";
		    orderTypeDetail += "  \"isRequire\":1,";
		  } else {
		    if($('#thanksCash_show_update').is(':checked')){
			  orderTypeDetail += "  \"isShow\":1,";
		    } else {
		      orderTypeDetail += "  \"isShow\":0,";
		    }
		    orderTypeDetail += "  \"isRequire\":0,";
		  }
		  if($('#thanksCashPrompt_update').val().trim()!=null) {
			orderTypeDetail += "  \"prompt\": \""+$('#thanksCashPrompt_update').val().trim()+"\",";
		  }
		  orderTypeDetail += "  \"seq\": 11";
		  orderTypeDetail += " }";
		}
		if($('#protectPrice_update').val().trim()!=null){
	 		  orderTypeDetail += ",{ ";
	 		  orderTypeDetail += " \"id\":"+$('#protectPrice_id').val().trim() + ",\"name\": \""+$('#protectPrice_update').val().trim()+"\",";
	 		  if($('#protectPrice_required_update').is(':checked')){
	 			orderTypeDetail += "  \"isShow\":1,";
	 		    orderTypeDetail += "  \"isRequire\":1,";
	 		  } else {
	 		    if($('#protectPrice_show_update').is(':checked')){
	 			  orderTypeDetail += "  \"isShow\":1,";
	 		    } else {
	 		      orderTypeDetail += "  \"isShow\":0,";
	 		    }
	 		    orderTypeDetail += "  \"isRequire\":0,";
	 		  }
	 		  if($('#protectPricePrompt_update').val().trim()!=null) {
	 			orderTypeDetail += "  \"prompt\": \""+$('#protectPricePrompt_update').val().trim()+"\",";
	 		  }
	 		  orderTypeDetail += "  \"seq\": 12";
	 		  orderTypeDetail += " }";
	 		}
		if($('#picture_update').val().trim()!=null){
 		  orderTypeDetail += ",{ ";
 		  orderTypeDetail += " \"id\":"+$('#picture_id').val().trim() + ",\"name\": \""+$('#picture_update').val().trim()+"\",";
 		  if($('#picture_required_update').is(':checked')){
 			orderTypeDetail += "  \"isShow\":1,";
 		    orderTypeDetail += "  \"isRequire\":1,";
 		  } else {
 		    if($('#picture_show_update').is(':checked')){
 			  orderTypeDetail += "  \"isShow\":1,";
 		    } else {
 		      orderTypeDetail += "  \"isShow\":0,";
 		    }
 		    orderTypeDetail += "  \"isRequire\":0,";
 		  }
 		  if($('#picturePrompt_update').val().trim()!=null) {
 			orderTypeDetail += "  \"prompt\": \""+$('#picturePrompt_update').val().trim()+"\",";
 		  }
 		  orderTypeDetail += "  \"seq\": 13";
 		  orderTypeDetail += " }";
 		}
		if($('#content_update').val().trim()!=null){
		  orderTypeDetail += ",{ ";
		  orderTypeDetail += "  \"id\":"+$('#content_id').val().trim() + ",\"name\": \""+$('#content_update').val().trim()+"\",";
		  if($('#content_required_update').is(':checked')){
			orderTypeDetail += "  \"isShow\":1,";
		    orderTypeDetail += "  \"isRequire\":1,";
		  } else {
		    if($('#content_show_update').is(':checked')){
			  orderTypeDetail += "  \"isShow\":1,";
		    } else {
		      orderTypeDetail += "  \"isShow\":0,";
		    }
		    orderTypeDetail += "  \"isRequire\":0,";
		  }
		  if($('#contentPrompt_update').val().trim()!=null) {
			orderTypeDetail += "  \"prompt\": \""+$('#contentPrompt_update').val().trim()+"\",";
		  }
		  orderTypeDetail += "  \"seq\": 14";
		  orderTypeDetail += " }";
		}
		if($('#addServices_update').val().trim()!=null){
 		  orderTypeDetail += ",{ ";
 		  orderTypeDetail += " \"id\":"+$('#addServices_id').val().trim() + ",\"name\": \""+$('#addServices_update').val().trim()+"\",";
 		  if($('#addServices_required_update').is(':checked')){
 			orderTypeDetail += "  \"isShow\":1,";
 		    orderTypeDetail += "  \"isRequire\":1,";
 		  } else {
 		    if($('#addServices_show_update').is(':checked')){
 			  orderTypeDetail += "  \"isShow\":1,";
 		    } else {
 		      orderTypeDetail += "  \"isShow\":0,";
 		    }
 		    orderTypeDetail += "  \"isRequire\":0,";
 		  }
 		  if($('#addServicesPrompt_update').val().trim()!=null) {
 			orderTypeDetail += "  \"prompt\": \""+$('#addServicesPrompt_update').val().trim()+"\",";
 		  }
 		  orderTypeDetail += "  \"seq\": 15";
 		  orderTypeDetail += " }";
 		}
		
		orderTypeDetail += "]";
		var allowTips;
		if($('#allowTips_update').is(':checked')){
			allowTips = 1;
		}else{
			allowTips = 0;
		}
   		var alltips = "["
		for(var i=0;i<n;i++){
			if($('#tipName'+i).val()!=null){
				alltips += "{\"tipName\":\""+$('#tipName'+i).val()+"\",\"tipspicture\":\"" + $("#tipspicture"+i).val() + "\",\"tipQueryName\":\"" 
				+ $('#tipQueryName'+i).val() + "\",\"ifCheck\":\"" + $('#ifCheck'+i).val() +"\"},";
			}
		}
   		alltips = alltips.substr(0,alltips.length-1)+"]";
   		if(alltips.length<3){
   			alltips = "";
   		}
   		console.log(alltips);
	$.post(ctx+'/errand/up/updateOrderType',
	{'id':$('#typeId').val(),'typeName':$('#typeName_update').val(),'typeSeq':$('#typeSeq_update').val(),'errandOrderTypeDetaileds':orderTypeDetail,
	'typepicture':typepicture_update,'otherServices':JSON.stringify(updateOtherService),
	'tips':alltips,'allowTips':allowTips
	},
	function(data){
       if(data.success){
    	    $('#update_orderType').modal("hide");
            $.scojs_message(data.message, $.scojs_message.TYPE_OK);
            setTimeout(function(){
				window.location.reload(true);
			}, 1000);
       }else{
            $.scojs_message(data.message, $.scojs_message.TYPE_ERROR);
           
       }
    },'json');
 });
$(document).on("click","#close_modal_update",function(){
	$('#update_orderType').modal("hide");
});
$("#close_modal_service_update").on('click',function(){
	$('#dialog_otherServises_update').modal("hide");
	$('#update_orderType').modal();
	$('#update_orderType').css({"overflow-y":"auto"});
});
Date.prototype.Format = function(fmt) 
{ 
  var o = { 
    "M+" : this.getMonth()+1,                 //月份 
    "d+" : this.getDate(),                    //日 
    "h+" : this.getHours(),                   //小时 
    "m+" : this.getMinutes(),                 //分 
    "s+" : this.getSeconds(),                 //秒 
    "q+" : Math.floor((this.getMonth()+3)/3), //季度 
    "S"  : this.getMilliseconds()             //毫秒 
  }; 
  if(/(y+)/.test(fmt)) 
    fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length)); 
  for(var k in o) 
    if(new RegExp("("+ k +")").test(fmt)) 
  fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
  return fmt; 
}
